package com.lbd99.data.lbd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lbd99.data.lbd.service.BProductService;
import com.lbd99.data.lbd.service.TUserService;
import com.lbd99.data.lbd.vo.SysAccount;
import com.lbd99.data.lbd.vo.TUser;

@Controller
@RequestMapping("bProduct")
public class BProductController {
	
	private static final Logger logger = LoggerFactory.getLogger(BProductController.class);

	@Autowired
    private BProductService bProductService;
	@Autowired
    private TUserService tUserService;
	
	/**
	 * 我要买卖列表：分页查询数据(挂单信息)
	 */
	@RequestMapping(value = "/getBProductList")
	@ResponseBody
	public Map<String, Object> getBProductList(String phone,int page,int rows,HttpSession httpSession){
		Map<String, Object> result = new HashMap<String, Object>();
		//拼装map条件
		Map<String,Object> map=new HashMap<String,Object>();
		if(StringUtils.isNotBlank(phone)){
			map.put("phone", StringUtils.trim(phone));
		}
		/*===================================================================================================*/
	     SysAccount sysAccount = (SysAccount)httpSession.getAttribute("SESSION_INFO_OBJECT");//获取当前登录的用户
	        if(sysAccount.getType()==1){//如果是普通管理员，用手机号查询出user信息
	        	TUser user = tUserService.selectByPhone(sysAccount.getTel());
	        	if(user!=null){
	        		//根据用户id查出该用户伞下的ID集合(包含自身)
	        		List<Integer> ids = tUserService.selectTreeIds(user.getId());
	        		if(ids!=null && ids.size()>0){
	        			map.put("ids",ids);
	        		}
	        	}
	        }
		 /*======================================================================================================*/
		PageHelper.startPage(page, rows);
		List<Map<String,Object>> list = bProductService.selectListByMap(map);
		PageInfo<Map<String,Object>> pages = new PageInfo<Map<String,Object>>(list);
		result.put("total", pages.getTotal());
		result.put("rows", pages.getList());
		return result;
	}
	
	
}
